import request from "@/utils/request"

const DICT_BASE_URL = "/api/object/com.siline.chimes/ChimesDict"

class DictAPI {
  /**
   * 获取字典分页列表
   *
   * @param data 查询参数
   * @returns 字典分页结果
   */
  static getPage(data: QueryCondition = {}) {
    return request<any, ResponseData<PageResult<DictVO[]>>>({
      url: `${DICT_BASE_URL}/paged_query`,
      method: "post",
      data,
    })
  }

  /**
   * 获取字典表单数据
   *
   * @param id 字典ID
   * @returns 字典表单数据
   */
  static getFormData(id: number) {
    return request<any, ResponseData<DictForm>>({
      url: `${DICT_BASE_URL}/select/${id}`,
      method: "get",
    })
  }

  /**
   * 新增字典
   *
   * @param data 字典表单数据
   * @returns 请求结果
   */
  static add(data: DictForm) {
    return request({
      url: `${DICT_BASE_URL}/insert`,
      method: "post",
      data: data,
    })
  }

  /**
   * 修改字典
   *
   * @param id 字典ID
   * @param data 字典表单数据
   * @returns 请求结果
   */
  static update(data: DictForm) {
    return request({
      url: `${DICT_BASE_URL}/update`,
      method: "post",
      data: data,
    })
  }

  /**
   * 删除字典
   *
   * @returns 请求结果
   */
  static deleteBy(data: QueryCondition) {
    return request({
      url: `${DICT_BASE_URL}/delete_by`,
      method: "post",
      data,
    })
  }

  /**
   * 获取字典的数据项
   *
   * @param typeCode 字典编码
   * @returns 字典数据项
   */
  static getOptions(code: string) {
    return request<any, ResponseData<OptionType[]>>({
      url: `/api/query/com.siline.chimes/FindDictDetailByDictName/search`,
      method: "post",
      data: {
        dict_name: code,
      },
    })
  }
}

export default DictAPI

/**
 * 字典分页对象
 */
export interface DictVO {
  dict_id?: number
  name?: string
  description?: string
  create_by?: string
  create_time?: Date
  update_by?: string
  update_time?: Date
}

/**
 * 字典
 */
export interface DictForm {
  dict_id?: number
  name?: string
  description?: string
}
